#pragma once
#include "core/CSerialization.h"
#include "Config.h"

struct Ver {
	int code = -1;

	template<class Archive>
	void serialize(Archive& archive) { archive(CEREAL_NVP(code)); }
};

struct ZhicheInfo {
	float width = -1;
	float length;
	float height;
	float maxX;
	float maxY;
	float maxZ;

	ZhicheInfo() = default;
	ZhicheInfo(float _width, float _length, float _height, float _maxX, float _maxY, float _maxZ) 
			  : width(_width), length(_length), height(_height), maxX(_maxX), maxY(_maxY), maxZ(_maxZ) {}

	template<class Archive>
	void serialize(Archive& archive) {
		archive(CEREAL_NVP(width), CEREAL_NVP(length), CEREAL_NVP(height), CEREAL_NVP(maxX), CEREAL_NVP(maxY), CEREAL_NVP(maxZ));
	}
};

class DiskCache {
public:
	static bool isVersionChanged() { return Config::Version_Code != getVerCode(); }

	static int getVerCode() {
		Ver version;
		CSerialization::deserialize(version, Config::Version_CachePath);
		return version.code;
	}

	static void updateVersion() {
		Ver version;
		version.code = Config::Version_Code;
		CSerialization::serialize(version, Config::Version_CachePath);
	}

	static ZhicheInfo getZhicheInfo() {
		ZhicheInfo zhicheInfo;
		CSerialization::deserialize(zhicheInfo, Config::View3D_ZhicheInfoPath);
		return zhicheInfo;
	}

	static void updateZhicheInfo(ZhicheInfo zhicheInfo) {// do not use const &, otherwise, affect json structure
		CSerialization::serialize(zhicheInfo, Config::View3D_ZhicheInfoPath);
	}
};